﻿using DataModel;
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace CuteWallpaperDemo.Models
{
    public class NotifyWindowBase : Window
    {
        public void Init(NotifyType type, string message)
        {
            this.NotifyType = type;
            this.Message = message;
            FontColor = SetFontColor();
            //SetPositionRelativeToOwner();
        }

        public NotifyType NotifyType { get; set; }

        public double CurrentTop {  get; set; }

        public string Message
        {
            get { return (string)GetValue(MessageProperty); }
            set { SetValue(MessageProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Message.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MessageProperty =
            DependencyProperty.Register("Message", typeof(string), typeof(NotifyWindowBase), new PropertyMetadata(""));



        public Brush FontColor
        {
            get { return (Brush)GetValue(FontColorProperty); }
            set { SetValue(FontColorProperty, value); }
        }

        // Using a DependencyProperty as the backing store for FontColor.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty FontColorProperty =
            DependencyProperty.Register("FontColor", typeof(Brush), typeof(NotifyWindowBase), new PropertyMetadata(new SolidColorBrush(Colors.White)));


        private Brush SetFontColor() => (NotifyType) switch
        {
            NotifyType.Success => new SolidColorBrush(Color.FromRgb(46, 204, 113)),
            NotifyType.Info => new SolidColorBrush(Color.FromRgb(30, 144, 255)),
            NotifyType.Warning => new SolidColorBrush(Color.FromRgb(249, 202, 36)),
            NotifyType.Error => new SolidColorBrush(Color.FromRgb(214, 48, 49)),
            _ => new SolidColorBrush(Colors.White)
        };

        protected virtual void SetPositionRelativeToOwner()
        {

        }

        public void MoveUpWindow(double start, double end)
        {
            DoubleAnimation slideInAnimation = new DoubleAnimation
            {
                From = start,
                To = end,
                Duration = new Duration(TimeSpan.FromSeconds(0.1)),
                FillBehavior = FillBehavior.Stop
            };
            slideInAnimation.Completed += (s, ev) => { this.ApplyAnimationClock(Window.TopProperty, null); this.Top = end; };
            this.BeginAnimation(Window.TopProperty, slideInAnimation);
        }
    }
}
